package com.group5.controller;


import com.group5.dao.PlatformMapper;
import com.group5.dao.UserssMapper;
import com.group5.pojo.ManufacturerQuerySellerResult;
import com.group5.pojo.Platform;
import com.group5.pojo.Userss;
import com.group5.service.BuyerService;
import com.group5.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manufacturer")
public class ManufacturerController {
    @Autowired
    PlatformMapper platformMapper;
    @Autowired
    UserssMapper userssMapper;
    BuyerService buyerService= new BuyerService();
    SellerService sellerService;

    /**
     * 前端提供厂商oid,后端返回出售过这个厂商的药品销售情况
     * @param username 厂商oid
     * @return 出售过该厂商药品的机构(卖方)+药品编号+该药品销售额
     */

    @GetMapping("/getManufacturerAndDrugSellPerformance")
    public List<ManufacturerQuerySellerResult> getManufacturerAndDrugSellPerformance(@RequestParam String username){
        List<Userss> list = userssMapper.selectByExample(buyerService.selectUserByUsernameExample(username));
        if(list.isEmpty()){
            return null;
        }
        return platformMapper.getManufacturerAndDrugSellPerformance(list.get(0).getOid());
    }
}
